package erpc

import (
	"context"
	"time"
)

// server
type RpcPieceStoreServer interface {
	Upload(requst UploadRequest, stream UploadStream) error
	Download(requst DownloadRequst, stream DownloadStream) error
}
type UploadStream interface {
	Recv() (*Chunk, error)
	Close()
	SendAndClose(result *UploadResult) error
}
type DownloadStream interface {
	Send(*Chunk) error
	Close()
	CloseSend() error
}

//client

type RpcPieceStoreClient interface {
	Upload(ctx context.Context, pieceName string, expireTime time.Time, rateBytePerSecond int64) (UploadClient, error)
	Download(ctx context.Context, pieceName string, rateBytePerSecond int64) (DownloadClient, error)
	Close() string
}
type UploadClient interface {
	Send(*Chunk) error
	CloseAndRecv() (*UploadResult, error)
}
type DownloadClient interface {
	Recv() (*Chunk, error)
	CloseAndRecv() error
}
type UploadRequest struct {
	PieceId    []byte
	ExpireTime int
}
type UploadResult struct {
	Hash []byte
}
type DownloadRequst struct {
	PieceId    []byte
	SpeedLimit int64
}

type Chunk struct {
	Offset int
	Data   []byte
	Done   int
}

//type PieceDownloadResponse struct {
//	Offset  int
//	Data    []byte
//	Done    int
//	PieceId []byte
//}
